package com.zzyl.service.impl;



import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.dto.ProjectPlansDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import lombok.val;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> pageFind(String name, Integer pageNum, Integer pageSize, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingProject> page =nursingProjectMapper.pageFind(name,status);
        PageResponse<NursingProjectVo> nursingProjectVoPageResponse = PageResponse.of(page, NursingProjectVo.class);
        return nursingProjectVoPageResponse;
    }

    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProject.setCreateTime(LocalDateTime.now());
        nursingProject.setUpdateTime(LocalDateTime.now());
        nursingProject.setCreateBy(1L);
        nursingProject.setUpdateBy(1L);
        nursingProjectMapper.add(nursingProject);
    }

    @Override
    public NursingProjectVo ById(Long id) {
       NursingProject nursingProject= nursingProjectMapper.ById(id);
        if(nursingProject!=null) {
            NursingProjectVo nursingProjectVo = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
            return nursingProjectVo;
        }
        return null;
    }

    @Override
    public void update(NursingProjectDto nursingProjectDto) {
      NursingProject nursingProject =  BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    @Override
    public void updatestatus(Long id, Integer status) {
        nursingProjectMapper.updatestatus(id,status);
    }

    @Override
    public List<NursingProject> all() {

        return nursingProjectMapper.all();
    }


}
